import enum_data.FormStatus;
import enum_data.MenuType;

import javax.swing.*;
import java.sql.SQLException;

/**
 * Created with IntelliJ IDEA.
 * User: valeriykuchma
 * Date: 10.03.13
 * Time: 23:14
 * To change this template use File | Settings | File Templates.
 */
public class MainTable extends JTable {

    @Override
    public boolean isCellEditable(int i, int i2) {
        return false;
    }

    public void openAdditionalForm(MenuType menu, FormStatus formMode){
        JDialog additionalForm = null;
        String userID = null;

        //Проверка выделена ли строка в таблице
        if (formMode == FormStatus.EDIT) {
            if (this.getSelectedRow() == -1) {
                return;
            }

            userID = (String) this.getValueAt(this.getSelectedRow(), 0);
        }

        try {
            switch (menu){
                case SPRAVOCHNIK_USERS:
                    if (formMode == FormStatus.NEW){
                            additionalForm = new Form_User("", FormStatus.NEW);// FormMain.FORM_MODE_NEW);
                    } else {
                            additionalForm = new Form_User(userID, FormStatus.EDIT);
                    }
                    break;
                case SPRAVOCHNIK_PRIVILEGIES:
                    if (formMode == FormStatus.NEW){
                        additionalForm = new Form_SingleData(userID, FormStatus.NEW);
                    } else {
                        additionalForm = new Form_SingleData(userID, FormStatus.EDIT);
                    }
                    break;

                default:
//                JOptionPane.showMessageDialog(null, "Ошибка модуля \"openAdditionalForm\"\nmenu - " + menu + " не существует!!!");
                    return;
            }
        } catch (SQLException e) {
            e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
        }

        additionalForm.setModal(true);
        additionalForm.pack();
        additionalForm.setVisible(true);

    }



}
